home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1453.dms / var1453.adf / AmigaDOS / Example5.c < prev    next >
C/C++ Source or Header  |  1992-05-02  |  3KB  |  85 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM System                  Amiga C Club       */
  7. /* Chapter: AmigaDOS                    Tulevagen 22       */
  8. /* File:    Example5.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-02                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to attach a short comment to a file. */
  21. /* A short file called "Letter.doc" will be created, and a short      */
  22. /* comment will be attached.                                          */
  23. /* To see the comment use the CLI command "List".                     */
  24.  
  25.  
  26. /* Declares BOOL: */
  27. #include <exec/types.h>
  28. /* Declares the FileHandle structure: */
  29. #include <libraries/dos.h>
  30.  
  31.  
  32. void main();
  33.  
  34. void main()
  35. {
  36.   struct FileHandle *file_handle;
  37.   char letter[ 8 ] = { 'D', 'e', 'a', 'r', ' ', 'S', 'i', 'r' };
  38.   long bytes_written;
  39.   BOOL ok;
  40.  
  41.  
  42.   /* Try to open file "Letter.doc" as a new file:     */
  43.   /* (If the file does not exist, it will be created. */
  44.   /* If it, on the the other hand, exist, it will be  */
  45.   /* overwritten.)                                    */
  46.   file_handle = (struct FileHandle *)
  47.     Open( "RAM:Letter.doc", MODE_NEWFILE );
  48.   
  49.   /* Have we opened the file successfully? */
  50.   if( file_handle == NULL )
  51.   {
  52.     printf( "Could not open the file!\n" );
  53.     exit();
  54.   }
  55.  
  56.  
  57.  
  58.   /* We have now opened a file, and are ready to start writing: */
  59.   bytes_written = Write( file_handle, letter, sizeof( letter ) );
  60.  
  61.   if( bytes_written != sizeof( letter ) )
  62.   {
  63.     printf( "Could not save the documment!\n" );
  64.     exit();
  65.   }
  66.   else
  67.     printf( "The documment was successfully saved!\n" );
  68.  
  69.  
  70.  
  71.   /* Attach a short comment: */
  72.   ok = SetComment( "RAM:Letter.doc", "A very short letter" );
  73.  
  74.   /* Check if the comment was successfully attached: */
  75.   if( !ok )
  76.     printf( "Could not attach the comment!\n" );
  77.   else
  78.     printf( "The comment was successfull attached to the file!\n" );
  79.  
  80.  
  81.  
  82.   /* Close the file: */
  83.   Close( file_handle );
  84. }
  85.